package com.scheduler.backend;

//import com.scheduler.backend.data.repository.*;
//import com.scheduler.backend.po.ItemProcess;
//import com.scheduler.backend.po.ProductProcess;
//import mypackage.*;
//import org.junit.jupiter.api.Test;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.boot.test.context.SpringBootTest;
//import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
//
//import java.text.ParseException;
//import java.text.SimpleDateFormat;
//import java.util.ArrayList;
//import java.util.List;
//
//
//@SpringBootTest(classes = {SchedulerApplication.class})
//@EnableJpaRepositories
public class SaveFromOldSystem {
//
//    @Autowired
//    private OrderRepository orderRepository;
//    @Autowired
//    private ItemRepository itemRepository;
//    @Autowired
//    private ItemProcessRepository itemProcessRepository;
//    @Autowired
//    private CraftRepository craftRepository;
//    @Autowired
//    private ProductProcessRepository productProcessRepository;
//    @Autowired
//    private ResourceRepository resourceRepository;
//    @Autowired
//    private ScheduleRepository scheduleRepository;
//    @Autowired
//    private SchedulePeopleListRepository peopleListRepository;

//    @Test
//    public void saveOrders() throws Exception_Exception {
//        OrderManagerService service = new OrderManagerServiceImpl().getDao();
//        List<Order> orderList = service.getOrderByAll();
//
//        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
//        List<com.scheduler.backend.po.Order> orders = new ArrayList<>();
//        orderList.forEach(oldOrder ->
//                {
//                    try {
//                        com.scheduler.backend.po.Order temp = com.scheduler.backend.po.Order.builder()
//                                .itemId(oldOrder.getItemId().toString())
//                                .orderId(oldOrder.getOrderId())
//                                .orderNum(oldOrder.getOrderNum())
//                                .deadline(simpleDateFormat.parse(oldOrder.getDeadline().substring(0, 10)))
//                                .deleted(0)
//                                .build();
//                        orders.add(temp);

//                        orderRepository.save(temp);
//                    } catch (ParseException e) {
//                        e.printStackTrace();
//                    }
//                }
//        );
//        //orderRepository.saveAll(orders);
//    }

//    @Test
//    public void saveResources() throws Exception_Exception {
//        ERPService service = new ERPServiceImpl().getDao();
//        List<People> peopleList = service.getPeopleByAll();
//        List<Equipment> equipmentList = service.getEquipmentByAll();

//
//        List<com.scheduler.backend.po.Resource> resources = new ArrayList<>();
//        peopleList.forEach(oldPeople ->
//                {
//                    com.scheduler.backend.po.Resource temp = com.scheduler.backend.po.Resource.builder()
//                            .resourceId(oldPeople.getResourceId())
//                            .resourceName(oldPeople.getResourceName() == null ? oldPeople.getLeaderName() : oldPeople.getResourceName())
//                            .resourceType(oldPeople.getResourceType().value())
//                            .resourceNum(oldPeople.getResourceNum())
//                            .groupId(oldPeople.getGroupId())
//                            .project(oldPeople.getProject())
//                            .attachedResource(oldPeople.getAttachedResource())
//                            .deleted(0)
//                            .build();
//                    resources.add(temp);
//                }
//        );
//
//        equipmentList.forEach(oldEquipment ->
//                {
//                    com.scheduler.backend.po.Resource temp = com.scheduler.backend.po.Resource.builder()
//                            .resourceId(oldEquipment.getResourceId())
//                            .attachedResource(oldEquipment.getAttachedResource())
//                            .project(oldEquipment.getProject())
//                            .resourceName(oldEquipment.getResourceName())
//                            .resourceType(oldEquipment.getResourceType().value())
//                            .resourceNum(oldEquipment.getResourceNum())
//                            .deleted(0)
//                            .build();
//                    resources.add(temp);
//                }
//        );
//        resourceRepository.saveAll(resources);
//    }

//    @Test
//    public void saveItems() throws Exception_Exception {
//        ERPService service = new ERPServiceImpl().getDao();
//        List<Item> itemList = service.getItemByAll();

//
//        List<com.scheduler.backend.po.Item> items = new ArrayList<>();
//        itemList.forEach(oldItem ->
//                {
//                    com.scheduler.backend.po.Item temp = com.scheduler.backend.po.Item.builder()
//                            .itemId(oldItem.getItemId())
//                            .itemDescription(oldItem.getItemDescription())
//                            .itemType(oldItem.getItemType().value())
//                            .preparationWay(oldItem.getObtainAccess().value())
//                            .unit(oldItem.getUint() == null ? null : oldItem.getUint().value())
//                            .deleted(0)
//                            .build();
//                    items.add(temp);
//                }
//        );
//        itemRepository.saveAll(items);
//    }
//
//    @Test
//    //craft & itemProcess & productProcess
//    public void saveProcessesAndCrafts() throws Exception_Exception {
//        ERPService service = new ERPServiceImpl().getDao();
//        List<ProductProgress> productProgressList = service.getBOMByAll();
//
//        List<com.scheduler.backend.po.Craft> crafts = new ArrayList<>();
//        List<ItemProcess> itemProcesses = new ArrayList<>();
//        List<ProductProcess> productProcesses = new ArrayList<>();
//        productProgressList.forEach(oldProduct ->
//                {
//                    ProductProcess tempProduct = ProductProcess.builder()
//                            .productId(oldProduct.getProductId() == null ? "" : oldProduct.getProductId())
//                            .deleted(0)
//                            .build();
//                    productProcesses.add(tempProduct);
//
//                    oldProduct.getCrafts().forEach(oldCraft ->
//                            {
//                                com.scheduler.backend.po.Craft tempCraft = com.scheduler.backend.po.Craft.builder()
//                                        .productId(oldProduct.getProductId())
//                                        .artifactName(oldCraft.getCraftName() == null ? "" : oldCraft.getCraftName())
//                                        .craftOrder(null)
//                                        .deleted(0)
//                                        .build();
//                                crafts.add(tempCraft);
//
//                                oldCraft.getItemProgresses().forEach(oldItem ->
//                                        {
//                                            ItemProcess tempItem = ItemProcess.builder()
//                                                    .itemId(oldItem.getItemId() == null ? "" : oldItem.getItemId())
//                                                    .itemNum(oldItem.getItemNum() == null ? null : Double.valueOf(oldItem.getItemNum()))
//                                                    .changeLineTime(oldItem.getChangeLineTime() == null ? null : Double.valueOf(oldItem.getChangeLineTime().substring(0, oldItem.getChangeLineTime().length() - 1)))
//                                                    .itemType(oldItem.getItemType() == null ? null : oldItem.getItemType().value())
//                                                    .resourceKind(oldItem.getResourceKind() == null ? null : oldItem.getResourceKind().value())
//                                                    .peopleNeeded(oldItem.getPeopleNeeded())
//                                                    .production(oldItem.getProductCapacity())
//                                                    .resourceName(oldItem.getResourceName())
//                                                    .resourcePriority(oldItem.getResourcePriority() == null ? null : Integer.valueOf(oldItem.getResourcePriority()))
//                                                    .resourceType(oldItem.getResourceKind() == null ? null : oldItem.getResourceKind().value())
//                                                    .unit(oldItem.getUint() == null ? null : oldItem.getUint().value())
//                                                    .deleted(0)
//                                                    .build();
//                                            itemProcesses.add(tempItem);
//                                        }
//                                );
//                            }
//                    );
//                }
//        );
//        craftRepository.saveAll(crafts);
//        itemProcessRepository.saveAll(itemProcesses);
//        productProcessRepository.saveAll(productProcesses);
//    }

//    @Test
//    public void saveSchedules() throws Exception_Exception {
//        ScheduleService service = new ScheduleServiceImpl().getDao();
//        List<Schedule> scheduleList = service.getScheduleByAll();
//
//        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm");
//        List<com.scheduler.backend.po.Schedule> schedules = new ArrayList<>();
//        scheduleList.forEach(oldSchedule ->
//                {
//                    try {
//                        System.out.println("start" + oldSchedule.getScheduleStart());
//                        System.out.println("end" + oldSchedule.getScheduleEnd());
//                        com.scheduler.backend.po.Schedule temp = com.scheduler.backend.po.Schedule.builder()
//                                .scheduleCode(oldSchedule.getScheduleCode())
//                                .scheduleName(oldSchedule.getScheduleName())
//                                .scheduleStart(oldSchedule.getScheduleStart() == null ? null : simpleDateFormat.parse(oldSchedule.getScheduleStart()))
//                                .scheduleEnd(oldSchedule.getScheduleEnd() == null ? null : simpleDateFormat.parse(oldSchedule.getScheduleEnd()))
//                                .deleted(0)
//                                .build();
//                        schedules.add(temp);
//                    } catch (ParseException e) {
//                        e.printStackTrace();
//                    }
//                }
//        );
//        scheduleRepository.saveAll(schedules);
//    }

//    @Test
//    public void saveSchedulePeopleLists() throws Exception_Exception {
//        ScheduleService service = new ScheduleServiceImpl().getDao();
//        List<SchedulePeopleList> schedulePeopleList = service.getSchedulePeopleListByAll();
//
//        List<com.scheduler.backend.po.SchedulePeopleList> schedulePeopleLists = new ArrayList<>();
//        schedulePeopleList.forEach(old ->
//                {
//                    String weekdays = old.getWeekDays().toString();
//                    com.scheduler.backend.po.SchedulePeopleList temp = com.scheduler.backend.po.SchedulePeopleList.builder()
//                            .resourceId(old.getResourceId())
//                            .scheduleName(old.getScheduleName())
//                            .weekdayList(weekdays)
//                            .deleted(0)
//                            .build();
//                    schedulePeopleLists.add(temp);
//                }
//        );
//        peopleListRepository.saveAll(schedulePeopleLists);
//    }
}
